package com.csair.seam.infrastructure.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;

import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {
	
    @Bean("indexApi")
    public Docket indexApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("1.基础")
                .apiInfo(apiInfo("包含基础信息、公共服务、以及登录登出操作等"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.csair.seam.controller.index"))
                .paths(PathSelectors.any())
                .build();
    }
    
    @Bean("mobileApi")
    public Docket mobileApi() {
        return new Docket(DocumentationType.SWAGGER_12)
                .groupName("2.移动端")
                .apiInfo(apiInfo("移动端相关服务接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.csair.seam.controller.mobile"))
                .paths(PathSelectors.any())
                .build();
    }
    
    @Bean("pcApi")
    public Docket pcApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("3.PC端")
                .apiInfo(apiInfo("PC端相关服务接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.csair.seam.controller.pc"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(String desc){
        return new ApiInfoBuilder()
                //页面标题
                .title("资产管家")
                //描述
                .description(desc)
                .termsOfServiceUrl("https://weam.csair.com")
                .contact(new Contact("实物资产开发团队","http://www.csair.com","*****@csair.com"))
                .version("1.0.0")
                .build();
    }
}
